import { is } from 'typescript-is'; ... const getText = (obj: Obj1 | Obj2): string => { if (is<Obj1>(obj)) { return obj1.message; } return obj2.text; };